"""
title:后台端订单管理Page
author:刘鑫海
date：2022/1/7
"""

from Common.Base import Base,open_browser
from Page.AdminLoginPage import AdminLoginPage
import time


url1="http://localhost:8080/ecshop/admin/privilege.php?act=login"


class BackOrder(Base):
    """封装表现层:制作定位器"""
    order_management_loc=('css selector','li[key="04_order"]')   #订单管理按钮
    order_list_loc=('css selector','#sub-menu-02_order_list > a')   #订单列表按钮
    order_number_loc=('id','order_sn')   #订单号输入框
    consignee_loc=('id','consignee')    #收货人输入框
    order_status_loc=('id','status')    #订单状态下拉框
    search_loc=('class name','button')  #搜索按钮


    #断言用
    background_order_no_loc=('css selector','#order_0')   #后台订单号
    background_payable_amount_loc=('css selector','#listDiv > table:nth-child(1) > tbody > tr:nth-child(3) > td:nth-child(5)')   #后台应付金额
    cargo_receiver_loc=('css selector','#listDiv > table:nth-child(1) > tbody > tr:nth-child(3) > td:nth-child(3) > a')   #收货人





    """封装操作层：针对表现层中的元素操作"""
    def click_order_management(self):
        """
        点击订单管理按钮
        :return:
        """
        self.driver.switch_to.frame('menu-frame')
        self.click(self.order_management_loc)

    def click_order_list(self):
        """
        点击订单列表按钮
        :return:
        """
        self.click(self.order_list_loc)

    def input_order_number(self,order_number):
        """
        输入订单号
        :param backstage_order_number: 订单号
        :return:
        """
        self.driver.switch_to.parent_frame()
        self.driver.switch_to.frame("main-frame")
        self.send_keys(self.order_number_loc,order_number)

    def input_consignee(self,consignee):
        """
        输入收货人
        :param consignee: 收货人
        :return:
        """
        self.send_keys(self.consignee_loc,consignee)

    def selects_order_status(self,text):
        """
        订单状态下拉框
        :param text: 下拉框文本值
        :return:
        """
        self.drop_down_list(self.order_status_loc,text)

    def click_search(self):
        """
        点击搜索按钮
        :return:
        """
        self.click(self.search_loc)
        time.sleep(5)

    def get_background_order_no_text(self):
        """
        获取后台订单号文本值
        :return:
        """
        return self.get_element_text(self.background_order_no_loc)

    def get_background_payable_amount_text(self):
        """
        获取后台应付金额文本值
        :return:
        """
        return self.get_element_text(self.background_payable_amount_loc)

    def get_cargo_receiver_text(self):
        """
        获取后台收货人文本值
        :return:
        """
        return self.get_element_text(self.cargo_receiver_loc)


if __name__ == '__main__':
    driver=open_browser()
    go_goods = AdminLoginPage(driver)
    go_goods.go_url(url1)
    backorder=BackOrder(driver)
    backorder.click_order_management()
    backorder.click_order_list()
    backorder.input_order_number("2022010755488")
    backorder.input_consignee("")
    backorder.selects_order_status("请选择...")
    backorder.click_search()
    print(backorder.get_background_order_no_text())
    print(backorder.get_background_payable_amount_text())
